import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import javax.xml.crypto.Data;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.Logger;

public class test {
    public static void main(String[] args) throws SQLException {
//        DataSource dataSource=new MysqlDataSource();
//        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306" +
//                "/bit32mall?serverTimezone=UTC&useSSl=false&characterEncoding=utf8");
//        ((MysqlDataSource)dataSource).setUser("root");
//        ((MysqlDataSource)dataSource).setPassword("123qwe...");
//        Connection connection=dataSource.getConnection();
//        String sql="select * from bag";
//        PreparedStatement statement=connection.prepareStatement(sql);
//        ResultSet resultSet=statement.executeQuery();
//        while(resultSet.next()) {
//            int a = resultSet.getInt("price");
//            int b = resultSet.getInt("inventory");
//            System.out.println(a + "\t" + b);
//        }
        //创建数据源
        DataSource dataSource =new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/bit32mall?serverTimezone=UTC" +
                "&characterEncoding=utf8&useSSl=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("123qwe...");
        //建立连接
        Connection connection=dataSource.getConnection();
        String sql="select *from bag";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        //执行sql
        ResultSet resultSet= preparedStatement.executeQuery();

        System.out.println(resultSet.next());
        while(resultSet.next()){
            resultSet.getInt("price");
            resultSet.getInt("inventory");
        }
    }
}
